import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hand_writing/database/database.dart';
import 'package:hand_writing/router/go_router.dart';
import 'package:hand_writing/view/index/index_provider.dart';
import 'package:provider/provider.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  final database = AppDatabase(); // 只创建一次
  runApp(MyApp(database: database));
}

class MyApp extends StatelessWidget {
  final AppDatabase database;

  const MyApp({Key? key, required this.database}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => IndexProvider(database),
      child: ScreenUtilInit(
        designSize: const Size(750, 1334),
        builder: (context, child) {
          return MaterialApp.router(
            debugShowCheckedModeBanner: false,
            title: '手记',
            routerConfig: router,
          );
        },
      ),
    );
  }
}
